/**********************************************************************
 * SailmiPIM - modular cross-platform feature Personal Information Manager Tools.
 * Copyright(C) 2006-2014  Georg Rudoy
 *
 * Distributed under the Boost Software License, Version 1.0.
 *(See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
 **********************************************************************/

#include "registerdialog.h"
#include <QDomDocument>
#include "util/sys/sysinfo.h"
#include "sailmipim/ihavediaginfo.h"
namespace SailmiPIM::Plugin::UserProxy
{
    RegisterDialog::RegisterDialog(QWidget *parent)
    : QDialog(parent)
	{
        userProxy = new UserProxyImp(this);
        Ui_.setupUi(this);
	}


    void RegisterDialog::accept()
    {
        if(Ui_.lineEdit_account->text().isEmpty()){
            Ui_.label_hint->setText("account is null");
            return;
        }
        if(Ui_.lineEdit_truename->text().isEmpty()){
            Ui_.label_hint->setText("truename is null");
            return;
        }
        if(Ui_.lineEdit_password->text().isEmpty()){
            Ui_.label_hint->setText("password is null");
            return;
        }
        if(Ui_.lineEdit_confirmPass->text().isEmpty()){
            Ui_.label_hint->setText("confirm password is null!");
            return;
        }
        if(Ui_.lineEdit_password->text()!=Ui_.lineEdit_confirmPass->text()){
            Ui_.label_hint->setText("password is not eq!");
            return;
        }
        UserInfo *userInfo = new UserInfo();
        userInfo->userAccount = Ui_.lineEdit_account->text();
        userInfo->userName = Ui_.lineEdit_truename->text();
        userInfo->userNick = Ui_.lineEdit_nickName->text();
        userInfo->userPass = Ui_.lineEdit_password->text();
        userInfo->userPhone = Ui_.lineEdit_phone->text();
        userInfo = userProxy->registerUser(userInfo);
        if(userInfo->isRegistered){
            emit registerSuccess();
            this->close();
        }
    }
}
